<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>数据字典管理 </title>
	<#include '/commons/include/head.ftl'>
</head>

<body>

	<div id="mainLayout" class="easyui-layout" data-options="fit: true">
	
		<div id="westPanel" data-options="region: 'west', title: '字典分类', split: true, minWidth: 215, maxWidth: 500" style="width: 215px;border-top:0px;">
			<div id="mainLayout" class="easyui-layout" data-options="fit: true">
			
				<div data-options="region: 'north', border: false" style="height: 48px; overflow: hidden;">
					<div>
						<div class="datagrid-toolbars" style="padding-top:2px;height:46px">
							<div class="toolbar-row">
								<div class="group">
									<a onclick="data_dict_reload();" href="javascript:;" class="bto"><i class="fa fa-refresh bto icon-green"></i>刷新</a>
									<div class="tools_separator"></div>
									<a onclick="datadict_form_dialog('add');" href="javascript:;" class="bto"><i class="fa fa-plus bto icon-green"></i>新增</a>
									<a onclick="datadict_form_dialog('update');" href="javascript:;" class="bto"><i class="fa fa-pencil bto icon-green1"></i>编辑</a>
									<a onclick="datadict_del();" href="javascript:;" class="bto"><i class="fa fa-trash bto icon-red"></i>删除</a>
								</div>
							</div>
						</div>
					</div>
				</div>
				
				<div data-options="region: 'center'" style="padding: 1px;border-top:1px solid #E6E6E6; border-left:0;border-right:0;border-bottom:0;">
				
					<div id="dataDict_tree"></div>
					
				</div>
			</div>
		</div>
		
		<div id="centerPanel_dictDetail" data-options="region: 'center', title: '字典引用编码：<span id=\'dictCode\' style=\'color:red;\'>无</span>'" style="border-top:0px;">
					
			<div id="dict_detail_dg">
				<div id="toolbars_dataDictDetail" style="display:none;">
					<form id="searchForm">
						<div class="datagrid-toolbars">
							<div class="toolbar-row">
								<div class="group">
									<a onclick="dict_detail_reload();" href="javascript:;" class="bto"><i class="fa fa-refresh bto icon-green"></i>刷新</a>
									<div class="tools_separator"></div>
									<a onclick="dict_detail_form_dialog('add');" href="javascript:;" class="bto"><i class="fa fa-plus bto icon-green"></i>新增</a>
									<a onclick="dict_detail_form_dialog('update');" href="javascript:;" class="bto"><i class="fa fa-pencil bto icon-green1"></i>编辑</a>
									<a onclick="dict_detail_del();" href="javascript:;" class="bto"><i class="fa fa-trash bto icon-red"></i>删除</a>
								</div>
							</div>
						</div>
					</form>
				</div>
			</div>
			
		</div>
	
	</div>
	
	
	<script>
	var $dataDict_tree, $dict_detail_dg ;
	$(function(){
        dataDict();
        dataDictDetail_datagrid();
	});
	
	
    function dataDict() {
        $dataDict_tree = $("#dataDict_tree").tree({
			method: "GET", url: "${ctx}/manager/system/datadict/tree",
			animate: true, lines: true,
            onClick: function (node) {
            	if(node.category == "project") {
            		$("#dictCode").html(node.code);
            		$dict_detail_dg.datagrid({url: "${ctx}/manager/system/datadict/datagrid/"+node.id});
            	} else {
            		$dict_detail_dg.datagrid('loadData', { total: 0, rows: [] }); 
            	}
            },
            onBeforeCollapse: function() {
            	//禁止折叠
            	return false ;
            },
            onLoadSuccess: function (node, data) {
            }
        });
    }
	
    function dataDictDetail_datagrid() {
		$dict_detail_dg = $("#dict_detail_dg").datagrid({
            method: "GET", idField: "id", fit: true, 
            border: false, striped:true, pageSize: 30, pageList: [30,40,50,100,200,500,1000], 
            pagination: true, rownumbers: true, toolbar: "#toolbars_dataDictDetail", remoteSort: true, 
            sortName: 'sorting', sortOrder: 'asc', queryParams: {},
            frozenColumns: [[
                { field: "ck", checkbox: true },
                { field: "id", title: "ID", width: 80, sortable: true, hidden: true },
            ]],
            columns: [[
                { field: "dictName", title: "项目名称", width: 180 },
                { field: "dictValue", title: "项目值", width: 180 },
                { field: "sortCode", title: "排序", width: 50, align: "center", sortable: true },
                { field: "createTime", title: "创建时间", width: 150, sortable: true, align: "center", formatter:function(value,row){
                	return (undefined != value?$.date.format(value, "yyyy-MM-dd HH:mm:ss"):"") ;	
                }},
                { field: "createUserName", title: "创建用户", width: 80, align: "center" },
                { field: "modifyTime", title: "修改时间", width: 150, sortable: true, align: "center", formatter:function(value,row){
                	return (undefined != value?$.date.format(value, "yyyy-MM-dd HH:mm:ss"):"") ;	
                }},
                { field: "modifyUserName", title: "修改用户", width: 80, align: "center" }
            ]],
            onLoadSuccess: function(){
            	$.fn.datagrid.extensions.onLoadSuccess.apply(this, arguments);
            	$dict_detail_dg.datagrid('unselectAll');$dict_detail_dg.datagrid('clearSelections');
            },
            enableHeaderClickMenu: true, enableHeaderContextMenu: true, enableRowContextMenu: false
        });
    }
	
    
    /**********************************数据字典*********************************/
    
    function data_dict_reload(){$dataDict_tree.tree("reload") ;}
    function datadict_form_dialog(formType) {
		var form_url = "${ctx}/manager/system/datadict/form";
		if(formType === "update") {
			var t = $dataDict_tree.tree("getSelected") ;
			if(t == null) {alertify.warning("请选择一条记录！");return;}
			
			form_url = "${ctx}/manager/system/datadict/form?id="+t.id;
		}
		
		var $d = $.easyui.showDialog({
			title: '<div class="icon-div"><i class="fa fa-th-large fa-120 pt-2 icon-blue"></i></div> 表单', 
			href: form_url, 
			iniframe: false, topMost: true, iconCls : '',
			width: 410, height: 290, maximizable: true,
            enableApplyButton: false, enableCloseButton: false, enableSaveButton: false,
            buttons : [ 
              { text : '<i class="fa fa-save fa-120 mt-6 icon-blue"></i> 保存', handler : function() { $.easyui.parent.submitForm($d, $dataDict_tree) ; } },
              { text : '<i class="fa fa-remove fa-120 mt-6 icon-red"></i> 关闭', handler : function() { $d.dialog('destroy'); } } 
           	]
        });
	}
	
	function datadict_del() {
		var node = $dataDict_tree.tree("getSelected") ;
		if(node == null) {alertify.warning("请选择一条记录！");return;}
		$.messager.confirm("您确定要进行该操作？", function (c) { 
			if(c) {
				$.easyui.loading({ msg: "数据删除中，请稍等..."});
				$.ajax({
					url: "${ctx}/manager/system/datadict/delete/"+node.id,
					type: "DELETE", dataType: "JSON",
					success: function(result) {
						if (result.status) {
							$dataDict_tree.tree("reload") ;
							alertify.success(result.message);
							$.easyui.loaded();
						} else {
							alertify.warning(result.message);
							$.easyui.loaded();
						}
					},
					complete: function(XMLHttpRequest, textStatus){},
					error: function(XMLHttpRequest, textStatus, errorThrown){
						$.easyui.loaded();
						if(XMLHttpRequest.status == 403) {
							$.messager.alert(XMLHttpRequest.statusText, XMLHttpRequest.responseText, "warning");
						} else {
							$.messager.alert("错误", XMLHttpRequest.status + "：发生未知错误", "error");
						}
					}
				});
			}
		});
	}
	
	
	/**********************************字典详细*********************************/
	
	function dict_detail_reload(){$dict_detail_dg.datagrid("reload") ;}
	function getIds() {
		var rows = $dict_detail_dg.datagrid('getChecked');
		var ids = [];
		if (rows.length > 0) {
			for ( var i = 0; i < rows.length; i++) {
				if(undefined != rows[i].id && ""!=rows[i].id) {
					ids.push(rows[i].id);
				}
			}
		}
		return ids ;
	}	
	
	function dict_detail_form_dialog(formType) {
		var form_url;
		
		if(formType === "add") {
			var node = $dataDict_tree.tree("getSelected") ;
			if(node != null) { 
				if(node.category == "catalog"){
					alertify.warning("该项为字典目录不能添加字典项目，请先建立字典项目");return;
				}
				form_url = "${ctx}/manager/system/datadict/form_detail?dataDictId="+node.id;
			} else {
				alertify.warning("请选择左侧字典列表在添加！");return;
			}
		} else {
			var ids = getIds() ;
			if(ids.length == 0) {alertify.warning("请选择一条记录！");return;}
			if(ids.length > 1) {alertify.warning("只能编辑一条记录！");return;}
			form_url = "${ctx}/manager/system/datadict/form_detail?id="+ids[0];
		}
		
		var $d = $.easyui.showDialog({
			title: '<div class="icon-div"><i class="fa fa-th-large fa-120 pt-2 icon-blue"></i></div> 表单', 
			href: form_url, 
			iniframe: false, topMost: true, iconCls : '',
			width: 410, height: 250, maximizable: true,
            enableApplyButton: false, enableCloseButton: false, enableSaveButton: false,
            buttons : [ 
              { text : '<i class="fa fa-save fa-120 mt-6 icon-green"></i> 应用', handler : function() { $.easyui.parent.submitForm($d, $dict_detail_dg, true) ; } },
              { text : '<i class="fa fa-save fa-120 mt-6 icon-blue"></i> 保存', handler : function() { $.easyui.parent.submitForm($d, $dict_detail_dg) ; } },
              { text : '<i class="fa fa-remove fa-120 mt-6 icon-red"></i> 关闭', handler : function() { $d.dialog('destroy'); } } 
           	]
        });
	}
	
	
	function dict_detail_del() {
		var ids = getIds() ;
		if(ids.length == 0) {alertify.warning("请选择一条记录！");return;}
		$.messager.confirm("您确定要进行该操作？", function (c) { 
			if(c) {
				$.easyui.loading({ msg: "数据删除中，请稍等..."});
				dict_detail_deletedAjax("${ctx}/manager/system/datadict/delete_detail_Batch", {"ids" : ids.join(',')}) ;
			}
		});
	}
	function dict_detail_deletedAjax(url, params) {
		console.info(params);
		$.ajax({
			url: url, data: params,
			type: "POST", dataType: "JSON",
			success: function(result) {
				if (result.status) {
					$dict_detail_dg.datagrid("unselectAll");$dict_detail_dg.datagrid("reload") ;
					alertify.success(result.message);
					$.easyui.loaded();
				} else {
					alertify.warning(result.message);
					$.easyui.loaded();
				}
			},
			complete: function(XMLHttpRequest, textStatus){},
			error: function(XMLHttpRequest, textStatus, errorThrown){
				$.easyui.loaded();
				if(XMLHttpRequest.status == 403) {
					$.messager.alert(XMLHttpRequest.statusText, XMLHttpRequest.responseText, "warning");
				} else {
					$.messager.alert("错误", XMLHttpRequest.status + "：发生未知错误", "error");
				}
			}
		});
	}
	
	</script>

</body>
</html>

